package org.yyj.action;

import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionSupport;
import org.yyj.dao.DlDao;
import org.yyj.dao.impl.DlDaoImpl;
import org.yyj.model.Dlb;

import java.util.Map;

public class LoginAction extends ActionSupport {
    //Dlb对象，用于存储Dlb属性的值
    private Dlb dlb;
    //生成其getter和setter犯法

    public Dlb getDlb() {
        return dlb;
    }

    public void setDlb(Dlb dlb) {
        this.dlb = dlb;
    }

    @Override
    public String execute() throws Exception {
        try {
            //得到Dao接口对象
            DlDao dlDao=new DlDaoImpl();
            //调用Dao中的方法
            Dlb user=dlDao.validate(dlb.getXh(),dlb.getKl());
            //若不为空，则保存到Session中
            if (user!=null){
                Map session=(Map) ActionContext.getContext().getSession();
                session.put("user",user);
                return SUCCESS;
            }else{
                return ERROR;
            }
        }catch (Exception e){
            e.printStackTrace();
            return ERROR;
        }


    }
}
